Crate clafrica_lib

source ·
Expand description

§Clafrica Lib

clafrica-lib is a collection of utilities to make handling of clafrica code more convenient.

Example

use clafrica_lib::{text_buffer, utils};

// Build a TextBuffer
let root = text_buffer::Node::default();
root.insert(vec!['a', 'f'], "ɑ".to_owned());
root.insert(vec!['a', 'f', '1'], "ɑ̀".to_owned());

// Bulk insert of data in the TextBuffer
let data = vec![["af11", "ɑ̀ɑ̀"], ["?.", "ʔ"]];
utils::build_map(data);

// or directly from a file
let data = utils::load_data("data/sample.txt")
                  .expect("Failed to load the clafrica code file");
let data = data.iter()
               .map(|e| [e[0].as_str(), e[1].as_str()])
               .collect();

utils::build_map(data);

// Traverse the tree
let node = root.goto('a').and_then(|e| e.goto('f'));
assert_eq!(node.unwrap().take(), Some("ɑ".to_owned()));

// Test our cursor
let mut cursor = text_buffer::Cursor::new(root, 10);
let code = "af1";
code.chars().for_each(|c| {cursor.hit(c);});
assert_eq!(cursor.state(), (Some("ɑ̀".to_owned()), 3, '1'));
assert_eq!(cursor.undo(), Some("ɑ̀".to_owned()));

Modules§